package oa.hleast.xswl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import oa.hleast.xswl.mapper.SysDictItemMapper;
import oa.hleast.xswl.pojo.domain.SysCommonConfig;
import oa.hleast.xswl.pojo.domain.SysDictItem;
import oa.hleast.xswl.service.ISysCommonConfigService;
import oa.hleast.xswl.service.ISysDictItemService;
import oa.hleast.xswl.service.ISysDictService;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
@AllArgsConstructor
public class SysDictItemServiceImpl extends ServiceImpl<SysDictItemMapper, SysDictItem> implements ISysDictItemService {

    private final ISysCommonConfigService commonConfigService;
    private final ISysDictService dictService;

    @Override
    public IPage<SysDictItem> list(Page<SysDictItem> page, SysDictItem dict) {
        List<SysDictItem> list = this.baseMapper.list(page,dict);
        page.setRecords(list);
        return page;
    }

    @Override
    public SysDictItem getDictItemByConfigKey(String configKey) {
        log.info("configKey = {}",configKey);
        SysCommonConfig commonConfig = commonConfigService.getByConfigKey(configKey);
        log.info("commonConfig = {}", commonConfig);

        SysDictItem dictItem = this.getById(commonConfig.getValue());
        log.info("dictItem = {}", dictItem);
        return dictItem;
    }

    @Override
    public SysDictItem getDictItemById(Long id) {
        SysDictItem dictItem = this.getById(id);

        return dictItem;
    }

    @Override
    public List<SysDictItem> getByDictByCode(String code) {

        List<SysDictItem> pojoList = this.list(new LambdaQueryWrapper<SysDictItem>()
                .eq(SysDictItem::getDictCode, code)
        );

        return pojoList;
    }

}
